window.onload = function () {
    $.validator.addMethod("userTest", function (value) {
            let reg = /^[\u4E00-\u9FA5\uF900-\uFA2D|\w]{2,20}$/;
            if (reg.test(value)) {
                return true;
            }
            return false;
        }, "用户名为6-12位的英文或数字");

        $.validator.addMethod("telTest", function (value) {
            let reg = /^1[3-9]\d{9}$/;
            if (reg.test(value)) {
                return true;
            }
            return false;
        }, "请输入正确的手机号");

        $.validator.addMethod("passwordTest", function (value) {
            let reg = /^[0-9a-z,\./!@#$%^&*]{6,12}$/;
            if (reg.test(value)) {
                return true;
            }
            return false;
        }, "密码格式有误");

        $('#form').validate({
            rules: {
                username: {
                    required: true,
                    userTest: true,
                    rangelength: [2, 20],
                },

                usertel: {
                    required: true,
                    telTest: true,
                },

                password: {
                    required: true,
                    passwordTest: true,
                    rangelength: [6, 12],
                },

                repeat: {
                    equalTo: "#password"
                }
            },

            messages: {
                username: {
                    required: "请填写用户名",
                    userTest: "请填写正确的用户名",
                    rangelength: "用户名长度为2-20位",
                },
                usertel: {
                    required: "请填写手机号",
                    telTest: "请输入正确的手机号",
                },
                password: {
                    required: "请输入密码",
                    // passwordTest: "请填写正确的密码",
                },
                repeat: {
                    equalTo: "请输入是相同的密码"
                }
            },

            submitHandler: function (form) {
                
                // form.submit();log1
                // console.log(1);
                let p = pAjax({
                    url: "/zc/regist.php",
                    type: "get",
                    data: {
                        username: username.value,
                        password: password.value,
                        usertel: usertel.value,
                    },
                });
                alert('欢迎加入小黑盒');
                location.href = '../html/login.html'
            }
        });
        



    

        
        
    // }
}

